<template>
  <div class="mui-numbox" data-numbox-min='1'>
    <button class="mui-btn mui-btn-numbox-minus" type="button">-</button>
    <input id="test" class="mui-input-numbox" type="number" :value="initcount" ref='nobox' @change="changed" />
    <button class="mui-btn mui-btn-numbox-plus" type="button">+</button>
  </div>
</template>


<script>
import mui from '../../../lib/mui/js/mui'
import { mapMutations } from 'vuex'

export default {
  data() {
    return {};
  },
  methods: {
    changed(){
      const val = parseInt(this.$refs.nobox.value)
      // 调用 mutations 方法，更新数量
      this.updateGoodsCount({id: this.id, count: val})
    },
    ...mapMutations(["updateGoodsCount"])
  },
  mounted(){
    // 当组件挂载到页面中，去初始化 数字框
    mui('.mui-numbox').numbox();
  },
  props:['initcount','id']
};
</script>

<style lang="scss" scoped>

</style>